package csdn;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test5 {
    public static void main(String[] args) {
        String pathname="D:\\javacode\\javacode\\IO_1\\test_1.txt";//文件路径
        String str="happy new year!";//要写入的内容
        FileOutputStream fileOutputStream=null;
        try {
            fileOutputStream = new FileOutputStream(pathname, false);//创建对象，不可追加
            //fileOutputStream.write(str.getBytes());
            fileOutputStream.write(str.getBytes(),0,str.length());

        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
